{template 'common/header'}
<ul class="nav nav-tabs">
	<li {if $operation == 'add'}class="active"{/if}><a href="{php echo $this->createWebUrl('shopping', array('op' => 'category','operation' => 'add'))}">添加分类</a></li>
	<li {if $operation == 'list'}class="active"{/if}><a href="{php echo $this->createWebUrl('shopping', array('op' => 'category','operation' => 'list'))}">管理分类</a></li>
</ul>
<div class="main">
	<div class="category">
		<form action="" method="post" onsubmit="return formcheck(this)">
			<div class="panel panel-default">
				<div class="panel-body table-responsive">
					<table class="table table-hover">
						<thead>
							<tr>
								<th style="width:10px;"></th>
								<th style="width:30px;">显示顺序</th>
								<th style="width:50px;">分类名称</th>
								<th style="width:50px;">状态</th>
								<th style="width:150px;">操作</th>
							</tr>
						</thead>
						<tbody>
						{loop $list $row}
						<tr>
							<td></td>
							<td><input type="text" class="form-control" name="displayorder[{$row['id']}]" value="{$row['displayorder']}"></td>
							<td>
								<img src="{php echo tomedia($row['thumb']);}" width='30' height="30" onerror="$(this).remove()" style='padding:1px;border: 1px solid #ccc;float:left;' />
								<div class="type-parent">{$row['name']}
								</div>
							</td>
							<td>
								<input type="checkbox" value="1"{if intval($row[enabled])==1} checked="checked"{/if} data="{$row[id]}"/>
							</td>
							<td>
								<a href="{php echo $this->createWebUrl('shopping', array('op' => 'category', 'operation' => 'add', 'id' => $row['id']))}" class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="bottom" title="编辑"><i class="fa fa-edit"></i>编辑</a>&nbsp;&nbsp;
								<a href="{php echo $this->createWebUrl('shopping', array('op' => 'category','operation' => 'delete', 'id' => $row['id']))}" onclick="return confirm('确认删除此分类吗？');return false;" class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="bottom" title="删除"><i class="fa fa-times"></i>删除</a>
							</td>
						</tr>
						{/loop}
						<tr>
							<td></td>
							<td colspan="4">
								<a href="{php echo $this->createWebUrl('shopping', array('op' => 'category','operation' => 'add'))}" class="btn btn-primary btn-sm"><i class="glyphicon glyphicon-plus"></i> 添加新分类</a>
							</td>
						</tr>
						<tr>
							<td></td>
							<td colspan="4">
								<input name="submit" type="submit" class="btn btn-primary" value="提交">
								<input type="hidden" name="token" value="{$_W['token']}" />
							</td>
						</tr>
						</tbody>
					</table>
				</div>
			</div>
		</form>
	</div>
</div>
<script type="text/javascript">
	require(['bootstrap.switch', 'util'], function($, u){
        $(function(){
            $(':checkbox').bootstrapSwitch();
            $(':checkbox').on('switchChange.bootstrapSwitch', function(e, state){
                $this = $(this);
                var id = $this.attr('data');
                var enabled = this.checked ? 1 : 0;
                // alert(hid);return false;
                var url = "{php echo $this->createWebUrl('shopping',array('op' => 'category','operation' => 'list'))}";
                $.post(url, {enabled: enabled, id: id}, function(resp){
                    if(resp != 'success') {
                        u.message('操作失败, 请稍后重试.')
                    }
                    {if !empty($module)}
                    else {
                        u.message('操作成功！');
                        window.setTimeout(function(){location.href = location.href;}, 800);
                    }
                    {/if}
                });
            });
            $('.btn').hover(function(){
                $(this).tooltip('show');
            },function(){
                $(this).tooltip('hide');
            });
        });
    });
</script>
{template 'common/footer'}
